package com.ctms.system.controller;

import com.ctms.common.utils.PageUtils;
import com.ctms.common.utils.Query;
import com.ctms.common.utils.ShiroUtils;
import com.ctms.system.domain.CourseDO;
import com.ctms.system.domain.UserDO;
import com.ctms.system.service.StudentScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RequestMapping("/studentScore")
@Controller
public class StudentScoreController {

    @Autowired
    StudentScoreService studentScoreService;

    @GetMapping("")
    public String studentScore(){
        return "sys/studentScore/studentScore";
    }

    @GetMapping("/list")
    @ResponseBody
    PageUtils list(@RequestParam Map<String,Object> params){
        UserDO userDO = ShiroUtils.getUser();
        int identity = userDO.getIdentity();
        //如果是管理员，显示所有课程的所有学生
        Query query = new Query(params);
        List<UserDO> list = studentScoreService.selectAllStuScore(query);
        int total = studentScoreService.count(query);
        PageUtils pageUtils = new PageUtils(list,total);
        return pageUtils;

     /*       //教师
            Query query = new Query(params);
            List<UserDO> userDOS = studentScoreService.selectAllStuScore(query);
            //去除未选自己课程的学生
            int userId = Integer.parseInt(Long.toString(userDO.getUserId()));
            List<CourseDO> courseDOS = studentScoreService.selectCourseByTea(userId);
            List<UserDO> list = new ArrayList<>();
            for (int i=0;i<userDOS.size();i++){
                for (int j=0;j<courseDOS.size();j++){
                    if (userDOS.get(i).getCourseName().equals(courseDOS.get(j).getCourseName())){
                        list.add(userDOS.get(i));
                    }
                }
            }
            int length = list.size();
            PageUtils pageUtils = new PageUtils(list,length);
            return pageUtils;*/


    }

}

